﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Threading;

namespace NB_Controller_Test
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : System.Windows.Window
    {
        //数据初始化
        //public MainUI mainUI = new MainUI();
        public MainUIEx mainUIEx = new MainUIEx();
        
        public static Dispatcher mUIDispather = null;        

        public MainWindow()
        {
            InitializeComponent();

            mUIDispather = Dispatcher.CurrentDispatcher;
        } 

        private void WndMain_ContentRendered(object sender, EventArgs e)
        {
            string strTitle_Info = GlobalFun.GetAppConfigValue("Title_Info");
            if(strTitle_Info.Length >= 3)
            {
                this.Title = strTitle_Info;
            }            

            this.contentContainer.Children.Add(mainUIEx);

            NetLink.GetNetLink().InitNetLink(mainUIEx.srcIP.Text);
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (MessageBox.Show("请确认是否保存了设备信息到Excel中\r\n确定要退出？", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                NetLink.GetNetLink().UnInitNetLink();
                mainUIEx.ExitMainUIEx();

                Environment.Exit(0);
            } 
            else
            {
                e.Cancel = true;
            }
        }
    }
}

